package com.wuhao.lib_common.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.wuhao.lib_common.listener.ScreenLockListener;


/**
 * @author zhangjianhao
 */
public class ScreenLockReceiver extends BroadcastReceiver {
    private String action = null;
    private ScreenLockListener listener = null;

    @Override
    public void onReceive(Context context, Intent intent) {
        action = intent.getAction();

        if (Intent.ACTION_SCREEN_OFF.equals(action)) {
            if (listener != null) {
                listener.onScreenLock();
            }
        } else if (Intent.ACTION_USER_PRESENT.equals(action)) {
            if (listener != null) {
                listener.onScreenOpen();
            }
        }
    }

    public void setListener(ScreenLockListener listener) {
        this.listener = listener;
    }
}
